package leetcode.tree;

/**
 * 获取二叉树的深度
 * @author 榆关
 **/
public class GetDeap {

    /**
     * 二叉树的深度，就是分别遍历左子树和右子树，子树的深度加1就是整个数的深度
     */
    public static void main(String[] args) {
        TreeNode root = new TreeNode();
        TreeNode left = new TreeNode();
        TreeNode right = new TreeNode();
        root.setLeft(left);
        root.setRight(right);
        TreeNode ll = new TreeNode();
        TreeNode lr = new TreeNode();
        left.setLeft(ll);
        left.setRight(lr);
        TreeNode rl = new TreeNode();
        TreeNode rr = new TreeNode();
        right.setLeft(rl);
        right.setRight(rr);
        TreeNode lll = new TreeNode();
        ll.setLeft(lll);

        System.out.println(solution(root));

    }

    public static int solution(TreeNode node){
        if(node == null){
            return 0 ;
        }else{
            int left  = solution(node.left);
            int right = solution(node.right);
            return Math.max(left,right) +1;
        }
    }
}
